package com.nowcoder.community.dao;

import com.nowcoder.community.entity.LoginTicket;
import org.apache.ibatis.annotations.*;

@Mapper
@Deprecated// 不推荐使用的意思
public interface LoginTicketMapper {
    /**
     * @Author hhwu
     * @Description //TODO 演示如何在java文件中直接写sql语句
     * @Date 14:45 2022/5/19
     * @Param
     * @return
     **/
    // 新建凭证
    @Insert({
            "insert into login_ticket (user_id, ticket, status, expired) values (#{userId}, #{ticket}, #{status}, #{expired});"
    })
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insertLoginTicket(LoginTicket loginTicket);

    // 根据凭证查询用户
    @Select({
            "select id, user_id, ticket, status, expired from login_ticket where ticket=#{ticket};"
    })
    LoginTicket selectByTicket(String ticket);

    // 更新用户凭证状态
    @Update({
            "update login_ticket set status = #{status} where ticket=#{ticket};"
    })
    int updateStatus(String ticket, int status);
}
